home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / bitstrg.zip / LCREBITA.C < prev    next >
C/C++ Source or Header  |  1989-06-05  |  936b  |  40 lines

  1. /*
  2.     librairie : bitstrg
  3.  
  4.     lcrebitarray -- allocation memoire pour champ de bits
  5.  
  6.                     Le parametre nombre de bits est de type unsigned long
  7.  
  8.     Attention : en Small Memory Model le champ Data est limite a 64Koctets
  9. */
  10.  
  11. #include <stdio.h>
  12. #include "bitstrg.h"
  13.  
  14. /*
  15.     Creation of an array of bit
  16.  
  17.     The array is initialized to all 0s
  18.     return a pointer on the array parameters structure or NULL if problem
  19. */
  20.  
  21. struct LSPARRAY* lcrebitarray(nbbit)
  22.     unsigned long     nbbit;        /* number of the last bit in the array */
  23. {
  24.     unsigned value;            /* number of element in array */
  25.  
  26.     struct LSPARRAY* pnt;
  27.  
  28.     value = (((long)nbbit+1) / SIZE )
  29.          + ((((long)nbbit+1) & (SIZE - 1)) ? 1 : 0);
  30.  
  31.     if((pnt = (struct LSPARRAY *) calloc (1,sizeof(struct LSPARRAY))) != NULL) {
  32.         if((pnt->pntarray = (ELEBAR*) calloc(value,sizeof(ELEBAR))) == NULL) {
  33.             free(pnt);
  34.             return(NULL);
  35.         }
  36.         pnt->numlbit = nbbit;
  37.     }
  38.     return(pnt);
  39. }
  40.